<?php

class Henry_CreateThemes {
	public static function create(&$viewOb,$module = 'default',$themes = 'default',$installFile = 'install.ini')
	{
		$themesPath = APPLICATION_PATH . '/templates/'.$module.'/'.$themes;
		$fileConfigPatch = $themesPath . '/'.$installFile;
		//Dung Zend_Config de doc cau hinh
		//Tham so thu 1: Duong dan chua file cau hinh
		//Tham so thu 2: vun can load cau hinh
		$configLayout = new Zend_Config_Ini ( $fileConfigPatch, 'template' );

		//Lay duong dan URL cua ung dung
		$request = new Zend_Controller_Request_Http(); 
		$realUrl = $request->getBaseUrl();

		$dirCss = $realUrl . $configLayout->url . $configLayout->dir->css;
		$dirJs 	= $realUrl . $configLayout->url . $configLayout->dir->js;
		$dirImg = $realUrl . $configLayout->url . $configLayout->dir->img;
		
		//Load cac ten file css trong file config
		$fileCss = $configLayout->file->css;
		//chuyen tu Object thanh Array
		if (!empty($fileCss))
		{
			$fileCss = $fileCss->toArray ();
			// Load file css vào template			
			foreach ($fileCss as $item)
			{
				$viewOb->headLink()->appendStylesheet($dirCss.$item);
			}
		}
		//Load cac ten file js trong file config
		$fileJs = $configLayout->file->js;
		if (!empty($fileJs))
		{
			//chuyen tu Object thanh Array
			$fileJs = $fileJs->toArray();
			// Load file css vào template
			
			foreach ($fileJs as $item)
			{
				$viewOb->headScript()->appendFile ( $dirJs . $item , 'text/javascript' );
			}
		}
		$viewOb->headMeta ()->appendHttpEquiv ( 'Pragma', 'no-cache' );
		$viewOb->headMeta ()->offsetSetHttpEquiv ( 1, 'Content-Type', 'text/html; charset=utf-8' );
		
		$viewOb->headTitle ( $configLayout->title );
		$viewOb->dirImg = $dirImg;
		$viewOb->dirJs = $dirJs;
		$viewOb->dirCss = $dirCss;
		//option cua Zend_Layout co 2 tham so
		//Tham so 1: Ten file layout (layout.phtml)
		//Tham so 2: duong den dan den file layout
		$option = array ('layout' => $configLayout->filename, 'layoutPath' => $themesPath );
		//Bat layout theo che do MVC
		$layout = Zend_Layout::startMvc ( $option );

	}
}

?>